package com.ruoyi.web.api;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.ItemNotFoundException;
import com.ruoyi.common.utils.ObjectUtil;
import com.ruoyi.course.domain.SysCourse;
import com.ruoyi.course.service.ISysCourseService;
import com.ruoyi.questionBank.domain.Question;
import com.ruoyi.questionBank.service.IQuestionService;
import com.ruoyi.questionBank.service.impl.QuestionServiceImpl;
import com.ruoyi.questionBank.vo.CourseQuestionVO;
import com.ruoyi.questionBank.vo.QuestionAnswerVO;
import com.ruoyi.questionBank.vo.QuestionListVO;
import com.ruoyi.web.controller.course.SysCourseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.List;
import java.util.Map;

/**
 * 试题
 */
@RestController
@RequestMapping("/api/question")
public class QuestionApi extends BaseController {
    @Autowired
    private IQuestionService questionService;

    /**
     * 试题列表
     * @return
     */
    @RequestMapping("/list")
    public AjaxResult list(QuestionListVO listVO)
    {
        listVO.setBankType(1); //训练题库
        List<Question> list = questionService.list(listVO);
        return AjaxResult.success(list);
    }

    /**
     * 提交答案
     * @return
     */
    @RequestMapping("/submit")
    public AjaxResult submit(@RequestBody CourseQuestionVO courseQuestionVO)
    {
        ObjectUtil.checkNull(courseQuestionVO.getCourseNo() ,"课程编号为空");
        if (CollectionUtils.isEmpty(courseQuestionVO.getAnswers()) && courseQuestionVO.getScores() == null) {
            new ItemNotFoundException("答案或成绩为空");
        }
        Map<String,String> map = questionService.submitAnswer(courseQuestionVO);
        return AjaxResult.success(map);
    }

}
